package ui

import (
	"gioui.org/layout"
	"gioui.org/widget"
	"gioui.org/widget/material"
)

type Button struct {
	*widget.Clickable
	btn *material.ButtonStyle

	key string
}

func NewButton(th *material.Theme, key, title string) *Button {
	clickable := new(widget.Clickable)
	btn := material.Button(th, clickable, title)
	return &Button{
		Clickable: clickable,
		btn:       &btn,
		key:       key,
	}
}

func (b *Button) Layout(gtx layout.Context) layout.Dimensions {
	if b.Clicked(gtx) {
		BUS.Publish(b.key, *b)
	}

	return b.btn.Layout(gtx)
}
